package com.yequan.work;

import com.yequan.compare.Person;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author yequan
 * @date 2021/01/06 11:16
 **/
public class StringUtil {

    public static void main(String[] args) {
//        sub();
//        foldTextTest();
//        charAt();

//        Float.parseFloat("");
        blank();
    }

    public static void blank(){
        String carType = "";
        System.out.println(StringUtils.isBlank(carType));

        String rideId = null;
        System.out.println(Long.parseLong(rideId));
    }

    public static void charAt() {
        String phone = "16786567";
        char c = phone.charAt(phone.length() - 1);
        System.out.println(c);
    }

    public static void foldTextTest() {
        String text1 = "朝来高科技产业园西区-西门";
        String text2 = "天津海昌极地海洋世界";
        String text3 = "天津海昌极地海洋世有有有有有好好有有有有有有";
        System.out.println(foldText(text1, 11));
        System.out.println(foldText(text2, 10));
        System.out.println(foldText(text3, 18));
    }

    public static String foldText(String text, int threshold) {
        if (StringUtils.isBlank(text)) {
            return text;
        }
        if (threshold < 3) {
            threshold = 10;
        }
        int length = text.length();
        if (length >= threshold) {
            int headIndex = 0;
            int tailIndex = 0;
            switch (threshold) {
                case 10:
                    //5,4
                    headIndex = 5;
                    tailIndex = 4;
                    break;
                case 11:
                    //5,5
                    headIndex = 5;
                    tailIndex = 5;
                    break;
                case 14:
                    //7,6
                    headIndex = 7;
                    tailIndex = 6;
                    break;
                case 16:
                    //8,7
                    headIndex = 8;
                    tailIndex = 7;
                    break;
                case 18:
                    //9,8
                    headIndex = 9;
                    tailIndex = 8;
                    break;
                case 21:
                    //10,10
                    headIndex = 10;
                    tailIndex = 10;
                    break;
                case 22:
                    //11,10
                    headIndex = 11;
                    tailIndex = 10;
                    break;
                default:
            }
            String headText = text.substring(0, headIndex);
            String tailText = text.substring(length - tailIndex, length);
            return headText + "..." + tailText;
        }
        return text;
    }

    public static void sub() {
        float receiveMoney = 1.0f;
        String bottomTips = String.format("请提醒乘客点击 “<b style=\\'color:#5C6A78\\'>确认到达</b>”。确认后，%s车费将在2小时内到账", receiveMoney);
        if (0.0f == receiveMoney || 0 == receiveMoney) {
            int flagIndex = bottomTips.indexOf("确认后");
            bottomTips = bottomTips.substring(0, flagIndex);
        }
        System.out.println(bottomTips);
    }

    public static String clearDepotInitiatorComment(String initiator_comment) {
        if (StringUtils.isBlank(initiator_comment)) {
            return initiator_comment;
        }
        String key = " 赶飞机/火车";
        if (initiator_comment.contains(key)) {
            String[] comments = initiator_comment.split("；");
            if (comments.length > 0) {
                StringBuilder newComments = new StringBuilder();
                for (String comment : comments) {
                    if (!comment.contains(key)) {
                        newComments.append(comment).append("；");
                    }
                }
                return newComments.toString();
            }
        }
        return initiator_comment;
    }

}
